package nowCoder;

import java.util.*;

/**
 * @Auther: zzx
 * @Date: 2024.03.24/3/10
 */
public class HJ98 {

    static Map<String,Prod> prodMap = new HashMap<>();
    static Map<Integer, Integer> coinMap = new HashMap<>();
    static {
        prodMap.put("A1",new Prod("A1",2,0));
        prodMap.put("A2",new Prod("A2",3,0));
        prodMap.put("A3",new Prod("A3",4,0));
        prodMap.put("A4",new Prod("A4",5,0));
        prodMap.put("A5",new Prod("A5",8,0));
        prodMap.put("A6",new Prod("A6",6,0));
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] ml = s.split(";");
        String init = ml[0];
        String[] inits = init.split(" ");
        if (!"r".equals(inits[0])){
            return;
        }
        for (int i = 1; i <= inits[1].split("-").length; i++) {
            Prod prod = prodMap.get("A" + i);
            prod.num = Integer.parseInt(inits[1].split("-")[i-1]);
        }
        String[] coins = inits[2].split("-");
        coinMap.put(1, Integer.parseInt(coins[0]));
        coinMap.put(2, Integer.parseInt(coins[1]));
        coinMap.put(5, Integer.parseInt(coins[2]));
        coinMap.put(10, Integer.parseInt(coins[3]));
        System.out.println(Error.S001.getMsg());
        int ye = 0;
        for (int i = 1; i < ml.length; i++) {
            String[] mlt = ml[i].split(" ");
            switch (mlt[0]) {
                case "c" : {
                    c(ye);
                    ye = 0;
                }
                case "p" : {
                    int coinn = Integer.parseInt(mlt[1]);
                    if (p(ye,coinn)) {
                        ye += coinn;
                    }
                }
                case "b" : {
                    ye = b(ye, mlt[1]);
                }
                case "q" : {
                    q(mlt[1]);
                }
                default : {
                    System.out.println(Error.E010.getMsg());
                }
            }
        }
    }
    public static void q(String type){
        if ("0".equals(type)){
            Collection<Prod> values = prodMap.values();
            values.stream().sorted(Comparator.comparing((Prod p)->p.num).reversed().thenComparing((Prod p)->p.name)).
                    forEach((Prod p)->{
                        System.out.println(p.name + " " + p.price + " " + p.num);
                    });
        }else if("1".equals(type)) {
            for (Map.Entry<Integer, Integer> entry : coinMap.entrySet()) {
                System.out.println(entry.getKey() + " yuan coin number=" + entry.getValue());
            }
        }else {
            System.out.println(Error.E010.getMsg());
        }
    }
    public static int b(int ye, String prod){
        if (!prodMap.containsKey(prod)){
            System.out.println(Error.E006.getMsg());
            return ye;
        }
        Prod pro = prodMap.get(prod);
        if (pro.num == 0){
            System.out.println(Error.E007.getMsg());
            return ye;
        }
        if (ye < pro.price){
            System.out.println(Error.E008.getMsg());
            return ye;
        }
        System.out.printf((Error.S003.getMsg()) + "%n",ye - pro.price);
        return ye - pro.price;
    }
    public static void c(int ye){
        if (ye < 1){
            System.out.println(Error.E009.getMsg());
            return;
        }
        int o = 0;
        int s = 0;
        int f = 0;
        int t = 0;
        while (ye > 0){
            if (ye >= 10 && coinMap.get(10) > 0) {
                t++;
                ye -=10;
            }else if (ye >= 5 && coinMap.get(5) > 0){
                f++;
                ye -= 5;
            }else if (ye >= 2 && coinMap.get(2) > 0){
                s++;
                ye -= 2;
            }else if (coinMap.get(1) > 0){
                o++;
                ye -= 1;
            }else
                break;
        }
        System.out.println(1 + " yuan coin number=" +o);
        coinMap.put(1,coinMap.get(1) - o);
        System.out.println(2 + " yuan coin number=" +s);
        coinMap.put(2,coinMap.get(2) - s);
        System.out.println(5 + " yuan coin number=" +f);
        coinMap.put(5,coinMap.get(5) - f);
        System.out.println(10 + " yuan coin number=" +t);
        coinMap.put(10,coinMap.get(10) - t);
    }
    public static boolean p(int ye,int coinn){
        switch (coinn){
            case 10 :{}
            case 5 :{
                Integer integer1 = coinMap.get(1);
                Integer integer2 = coinMap.get(2);
                if ((integer1 + integer2 * 2) < coinn){
                    System.out.println(Error.E003.getMsg());
                    return false;
                }
            }
            case 2:{}
            case 1:{
                for (Map.Entry<String, Prod> entry : prodMap.entrySet()) {
                    if (entry.getValue().num > 0){
                        System.out.printf(Error.S002.getMsg() + "%n",ye+coinn);
                        coinMap.put(coinn,coinMap.get(coinn)+1);
                        return true;
                    }
                }
                System.out.println(Error.E005.getMsg());
                return false;
            }
            default:{
                System.out.println(Error.E002.getMsg());
            }
        }
//        if (ye == 5 || ye == 10){
//            Integer integer1 = coinMap.get(1);
//            Integer integer2 = coinMap.get(2);
//            if ((integer1 + integer2 * 2) < ye){
//                System.out.println(Error.E003.getMsg());
//                return false;
//            }
//            for (Map.Entry<String, Prod> entry : prodMap.entrySet()) {
//                if (entry.getValue().num > 0){
//                    System.out.println(Error.S002.getMsg());
//                    return true;
//                }
//            }
//            System.out.println(Error.E005.getMsg());
//        } else if (ye == 1 || ye == 2) {
//            for (Map.Entry<String, Prod> entry : prodMap.entrySet()) {
//                if (entry.getValue().num > 0){
//                    System.out.println(Error.S002.getMsg());
//                    return true;
//                }
//            }
//            System.out.println(Error.E005.getMsg());
//        } else {
//            System.out.println(Error.E002.getMsg());
//        }
        return false;
    }
    static class Prod{
        public String name;
        public Integer price;
        public Integer num;

        public Prod(String name, Integer price, Integer num) {
            this.name = name;
            this.price = price;
            this.num = num;
        }
    }
}
enum Error{
    E010("E010:Parameter error"),
    E009("E009:Work failure"),
    E008("E008:Lack of balance"),
    E007("E007:The goods sold out"),
    E006("E006:Goods does not exist"),
    E005("E005:All the goods sold out"),
    E003("E003:Change is not enough, pay fail"),
    E002("E002:Denomination error"),
    S003("S003:Buy success,balance=%s"),
    S002("S002:Pay success,balance=%s"),
    S001("S001:Initialization is successful");
    private String msg;
    Error(String msg) {
        this.msg = msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public String getMsg() {
        return msg;
    }
}
